package com.polaris.live.adapter

import android.view.View
import com.bumptech.glide.Glide
import com.polaris.live.R
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.common.ext.autoDp
import com.polaris.live.common.util.AppCodeUtils
import com.polaris.live.constant.LiveConst
import com.polaris.live.databinding.AdapterLiveDrawerBinding
import com.polaris.live.resp.back_resp.DisplayUserBean
import com.polaris.live.utils.CommonUtils
import com.polaris.live.utils.image.loadWejoyImage
import com.polaris.live.widget.LevelView

/**
 * LiveDrawerAdapter
 *
 * @author Created by 半仙 on 2023/10/10/010 10:18
 */
class LiveDrawerAdapter(
    private val mIsLive: Boolean = false,
) : BaseBindingAdapter<AdapterLiveDrawerBinding, DisplayUserBean>() {

    override fun convert(holder: VBViewHolder<AdapterLiveDrawerBinding>, item: DisplayUserBean) {
        holder.vb.apply {
            Glide.with(userCover.context)
                .loadWejoyImage(item.cover)
                .into(userCover)
            widgetState.setState(item)
            when (item.roomType) {
                LiveConst.RoomType.NORMAL -> {
                    roomTag.visibility = View.GONE
                    roomTag.setImageResource(0)
                }

                LiveConst.RoomType.AGENCY -> {  //公会
                    roomTag.visibility = View.VISIBLE
                    if (AppCodeUtils.isAR()) {
                        roomTag.setImageResource(R.drawable.family_tag_ar)
                    } else {
                        roomTag.setImageResource(R.drawable.family_tag)
                    }
                }

                LiveConst.RoomType.OFFICIAL -> { //官方
                    roomTag.visibility = View.VISIBLE
                    if (AppCodeUtils.isAR()) {
                        roomTag.setImageResource(R.drawable.sala_tag_ar)
                    } else {
                        roomTag.setImageResource(R.drawable.sala_tag)
                    }
                }

                else -> {
                    roomTag.visibility = View.GONE
                    roomTag.setImageResource(0)
                }
            }
            nickName.text = item.roomName
            vipView.setVipLevel(item.base.vipLevel, 45.autoDp, 14.autoDp)
            country.setCountry(item.base.country)
            if (CommonUtils.isMan(item.base.sex)) {
                level.setRichsLevel(item.base.richs, LevelView.LEVEL_VIEW_SMALL)
            } else {
                level.setCharmsLevel(item.base.charms, LevelView.LEVEL_VIEW_SMALL)
            }
            livingCount.text = item.stayUser.toString()
            widgetSubscript.setUserSymbol(item.symbol)
            val layout = relCenter.layoutParams
            if (!mIsLive) {
                layout.width = 140.autoDp
                layout.height = 140.autoDp
                roomFrame.setRoomFrame(item.base.roomFrame)
            } else {
                layout.width = 145.autoDp
                layout.height = 191.autoDp
            }
            relCenter.layoutParams = layout
        }
    }
}